package Text4;
import java.util.*;
public class Main {
    static int N = 210,n,m,q;
    static int[][] g = new int[N][N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        q = scanner.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if(i==j){
                    g[i][j]=0;
                }else {
                    g[i][j]=0x3f3f3f3f;
                }
            }
        }
        while (m-->0){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            g[a][b] = Math.min(g[a][b],c);
        }
        floyd();
        while(q-->0){
            int x=scanner.nextInt();
            int y=scanner.nextInt();
            if(g[x][y]>0x3f3f3f3f/2){
                System.out.println("impossible");
            }else {
                System.out.println(g[x][y]);
            }
        }
    }

    private static void floyd() {
        for (int k = 1; k <=n ; k++) {
            for (int i = 1; i <=n ; i++) {
                for (int j = 1; j <=n ; j++) {
                    g[i][j]=Math.min(g[i][j],g[i][k]+g[k][j]);
                }
            }
        }
    }
}